//
//  YZESuifangGanzangTableViewController.m
//  yilutongxing
//
//  Created by T&J on 2017/6/5.
//  Copyright © 2017年 YZE. All rights reserved.
//
#import <QMUITips.h>
#import "CommonDefine.h"
#import "DataUtils.h"
#import "IQActionSheetPickerView.h"
#import "YZESuifangGanzangTableViewController.h"
#import "YZESuifangTimeTypeCell.h"
#import "DzyImgPicker.h"
#import "RPLiverSuifangBean.h"
#import "DailyIndicatorViewController.h"
#import "RoutineBloodViewController.h"
#import "UrinalysisViewController.h"
#import "LiverViewController.h"
#import "RenalViewController.h"
#import "BloodsugarViewController.h"
#import "BloodfatViewController.h"
#import "TumorMarkerViewController.h"
#import "ImSupViewController.h"
#import "VirusInflectionViewController.h"
#import "LiverTranSonoViewController.h" //移植肝超声检查
#import "LiverAbnormalEchoViewController.h" //肝脏异常回声光团
#import "TabletPlanViewController.h" //用药方案
#import "RoutineBloodViewController.h"
#import "YZESuifangTimeTypeCell.h"
#import "SinglelineTextFormViewController.h"

#define URL_GetLiverSuifangData @"/api/liverGrafting"

@interface YZESuifangGanzangTableViewController ()<IQActionSheetPickerViewDelegate, DzyImgDelegate, SDWebImageManagerDelegate, TabletPlanViewBackDelegate,
                                                    DailyIndicatorControllerDelegate, RoutineBloodViewControllerDelegate,
                                                    UrinalysisViewControllerDelegate, LiverViewControllerDelegate,
                                                    RenalViewControllerDelegate, BloodsugarViewControllerDelegate,
                                                    BloodfatViewControllerDelegate, TumorMarkerViewControllerDelegate,
                                                    ImSupViewControllerDelegate, LiverTranSonoViewControllerDelegate,
                                                    LiverAbnormalEchoViewControllerDelegate, VirusInflectionViewControllerDelegate,
                                                    SinglelineTextFormViewControllerDelegate>
{
    NSComparator cr;//中文拼音首字母排序
}
@property (nonatomic, assign) BOOL isAdd; //是否新增
@property (nonatomic, strong) NSArray *checkItemArr;
@property (nonatomic, strong) NSMutableArray *picNameArr;
@property (nonatomic, strong) NSMutableDictionary *imgPickerDic;
@property (nonatomic, strong) NSMutableArray *imgArr;

@property (nonatomic, strong) RPLiverSuifangBean *liverSuifang;
@property(nonatomic, strong) NSDictionary *picPropertyNameFlectDic;//缓存模型中数据类型是图片的属性与中文名映射
@property(nonatomic, strong) NSMutableDictionary *picPropertyNameIndexDic;//缓存模型中数据类型是图片的属性索引
@property(nonatomic, strong) NSArray *picPropertyArr;//临时存储模型中数据类型是图片的属性值
@property(nonatomic, strong) NSMutableDictionary *picCacheDic;//uiimage的缓存
@property(nonatomic, strong) NSMutableArray *picCacheArr;//UIImageView的缓存
@property(strong, nonatomic) NSMutableArray *indexArr;//缓存图片控件与索引数组
@end

@implementation YZESuifangGanzangTableViewController

- (instancetype)initWithType:(BOOL)isAdd{
    self = [super init];
    if (self) {
        self.isAdd = isAdd;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //样式设置
    self.title = @"肝脏移植随访";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    UIBarButtonItem *submit = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStyleDone target:self action:@selector(submit)];
    self.navigationItem.rightBarButtonItem = submit;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //定义中文排序函数
    cr = ^(id l, id r){
        return [l localizedCompare:r];
    };
    
    //准备数据
    self.imgPickerDic = [NSMutableDictionary dictionary];
    self.checkItemArr = @[@"血常规",@"肝功能",@"肾功能",@"血脂",@"日常指标",@"尿常规",@"血糖",@"肿瘤指标",
                          @"免疫抑制剂浓度",@"病毒感染",@"移植肝超声检查"];
    NSArray *picItems = @[@"肝脏其它异常", @"肝脏CT", @"肺部CT/胸片", @"全身骨扫描"];
    picItems = [picItems sortedArrayUsingComparator:cr];//按拼音首字母排序
    self.picNameArr = [NSMutableArray array];
    [self.picNameArr addObjectsFromArray:picItems];
    [self.picNameArr addObject:@"其它"];
    
    if (_isAdd) {
        _liverSuifang = [RPLiverSuifangBean new];
    }
    else {
        [[YZENetwork sharedInstace]getRequestWithUrl:[NSString stringWithFormat:@"%@%@/%ld",BASE,URL_GetLiverSuifangData,self.suifangId]
                                          parameters:nil
                                            delegate:self
                                          requestTag:1
                                        successBlock:^(id responseObject)
         {
             self.liverSuifang = [RPLiverSuifangBean mj_objectWithKeyValuesAdd:responseObject];
             self.picPropertyArr = @[
                                     _liverSuifang.otherAbnormalities?_liverSuifang.otherAbnormalities:@"",
                                     _liverSuifang.liverCT?_liverSuifang.liverCT:@"",
                                     _liverSuifang.lungCT?_liverSuifang.lungCT:@"",
                                     _liverSuifang.boneImaging?_liverSuifang.boneImaging:@"",
                                     _liverSuifang.other?_liverSuifang.other:@""
                                     ];
             self.picCacheDic = [NSMutableDictionary dictionary];
             self.picCacheArr = [NSMutableArray array];
             [self.tableView reloadData];
         }];
    }
}

- (void)viewWillAppear:(BOOL)animated{
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)submit{
    NSDictionary *paramDic = _liverSuifang.mj_keyValuesAdd;
    NSString *url = [NSString stringWithFormat:@"%@%@", BASE, URL_GetLiverSuifangData];
    if (_isAdd) {
        [[YZENetwork sharedInstace]postRequestWithUrl:url parameters:paramDic delegate:self requestTag:2 successBlock:^(id responseObject) {
            [QMUITips showSucceed:@"已提交" inView:self.view hideAfterDelay:1];
        }];
    }
    else {
        [[YZENetwork sharedInstace]putRequestWithUrl:url parameters:paramDic delegate:self requestTag:2 successBlock:^(id responseObject) {
            [QMUITips showSucceed:@"已提交" inView:self.view hideAfterDelay:1];
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [self.picCacheArr removeAllObjects];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 10;
    }
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section==0 || section==1 || section==8 || section==10) {
        return 1;
    }
    if (section==2) {
        return self.checkItemArr.count;
    }
    if (section==9) {
        return 5;
    }
    return  1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat h = 44;
    if (indexPath.section==0) {
        if (SCREEN_WIDTH==320) {
            h = 218;
        }
        else
            h = 171;
    }
    else if (indexPath.section>=3 && indexPath.section<=7){
        h = 160;
    }
    else if (indexPath.section==9){
        if (indexPath.row==2 || indexPath.row==4) {
            h = 160;
        }
    }
    return h;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    NSString *identifier = [NSString stringWithFormat:@"cell%ld%ld",(long)indexPath.section,(long)indexPath.row];
    cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    NSNumber *index = [NSNumber numberWithInteger:(indexPath.section*10000+indexPath.row)];//图片控件索引
    
    if (indexPath.section==0) {
        identifier = @"suifang_timetype_cell";
        cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            [tableView registerNib:[UINib nibWithNibName:@"YZESuifangTimeTypeCell" bundle:nil] forCellReuseIdentifier:identifier];
            cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            ((YZESuifangTimeTypeCell*)cell).btn6.tag = ROWINDEX(indexPath);
            [((YZESuifangTimeTypeCell*)cell).btn6 addTarget:self action:@selector(timeTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    else if (indexPath.section==1){
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"随访日期";
        }
        
        cell.detailTextLabel.text = _liverSuifang.visitTime;
    }
    else if (indexPath.section==2){
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = self.checkItemArr[indexPath.row];
        }
    }
    else if (indexPath.section>=3 && indexPath.section<=7){//要上传图片的section
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            UIView *cv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
            UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 6, 200, 20)];
            [title setFont:[UIFont systemFontOfSize:17]];
            title.text = self.picNameArr[indexPath.section-3];
            [cv addSubview:title];
            DzyImgPicker *picker = [self createImgPicker];
            picker.tag = ROWINDEX(indexPath);
            [self.imgPickerDic setObject:picker forKey:index];
            [cv addSubview:picker];
            [cell.contentView addSubview:cv];
            [self.picPropertyNameIndexDic setObject:[self.picPropertyNameFlectDic objectForKey:title.text]
                                             forKey:[NSNumber numberWithInteger:picker.tag]
             ];
        }
        
        if (![_picCacheDic objectForKey:index]) {
            NSString *pkey_zh = self.picNameArr[indexPath.section-3];
            NSString *pkey = [self.picPropertyNameFlectDic objectForKey:pkey_zh];
            NSString *urlStr = [_liverSuifang valueForKey:pkey];
            [self requestPictures:urlStr ctrlIndex:index];
        }
        
    }
    else if (indexPath.section==8){
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.textLabel.text = @"用药方案";
        }
    }
    else if (indexPath.section==9){
        if (indexPath.row==0) {
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                [cell.textLabel setFont:[UIFont systemFontOfSize:17 weight:1]];
                cell.textLabel.text = @"特殊事件";
            }
        }
        else if (indexPath.row==1){
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = @"再次入院事件";
            }
        }
        else if (indexPath.row==2){
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 6, 200, 30)];
                [title setFont:[UIFont systemFontOfSize:17]];
                title.text = @"上传出院记录";
                [cell.contentView addSubview:title];
                DzyImgPicker *picker = [self createImgPicker];
                picker.tag = ROWINDEX(indexPath);
                [_imgPickerDic setObject:picker forKey:index];
                [cell.contentView addSubview:picker];
                [self.picPropertyNameIndexDic setObject:@"leaveRecord" forKey:[NSNumber numberWithInteger:picker.tag]];
            }
            
            if (![_picCacheDic objectForKey:index]) {
                [self requestPictures:_liverSuifang.leaveRecord?_liverSuifang.leaveRecord:@"" ctrlIndex:index];
            }
        }
        else if (indexPath.row==3) {
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                cell.textLabel.text = @"其它事件";
            }
        }
        else {
            if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 6, 200, 30)];
                [title setFont:[UIFont systemFontOfSize:17]];
                title.text = @"上传报告";
                [cell.contentView addSubview:title];
                DzyImgPicker *picker = [self createImgPicker];
                picker.tag = ROWINDEX(indexPath);
                [_imgPickerDic setObject:picker forKey:index];
                [cell.contentView addSubview:picker];
                [self.picPropertyNameIndexDic setObject:@"report" forKey:[NSNumber numberWithInteger:picker.tag]];
            }
            
            if (![_picCacheDic objectForKey:index]) {
                [self requestPictures:_liverSuifang.report?_liverSuifang.report:@"" ctrlIndex:index];
            }
        }
    }
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {
        IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
        [picker setTag:ROWINDEX(indexPath)];
        [picker setActionSheetPickerStyle:IQActionSheetPickerStyleDatePicker];
        [picker show];
    }
    else if (indexPath.section==2) {
        switch (indexPath.row) {
            case 0: //血常规
            {
                RoutineBloodViewController *v = [RoutineBloodViewController new];
                v.delegate = self;
                v.routineBlood = _liverSuifang.routineBloodDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 1: //肝功能
            {
                LiverViewController *v = [LiverViewController new];
                v.delegate = self;
                v.liver = _liverSuifang.liverDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 2: //肾功能
            {
                RenalViewController *v = [RenalViewController new];
                v.delegate = self;
                v.renal = _liverSuifang.renalDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 3: //血脂
            {
                BloodfatViewController *v = [BloodfatViewController new];
                v.delegate = self;
                v.bloodfat = _liverSuifang.bloodFatDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 4: //日常指标
            {
                DailyIndicatorViewController *v = [DailyIndicatorViewController new];
                v.delegate = self;
                v.dailyIndicator = _liverSuifang.dailyIndicatorDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 5: //尿常规
            {
                UrinalysisViewController *v = [UrinalysisViewController new];
                v.delegate = self;
                v.urinalysis = _liverSuifang.urinalysisDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
            case 6: //血糖
            {
                BloodsugarViewController *v = [BloodsugarViewController new];
                v.delegate = self;
                v.bloodsugar = _liverSuifang.bloodSugarDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 7: //肿瘤标志物
            {
                TumorMarkerViewController *v = [TumorMarkerViewController new];
                v.delegate = self;
                v.tumormarker = _liverSuifang.tumorMarkerDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 8: //免疫抑制剂浓度
            {
                ImSupViewController *v = [ImSupViewController new];
                v.delegate = self;
                v.imsup = _liverSuifang.imSupConcentrationDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 9: //病毒感染
            {
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"virusinflection" bundle:[NSBundle mainBundle]];
                VirusInflectionViewController *v = [sb instantiateViewControllerWithIdentifier:@"virusinflectionVC"];
                v.delegate = self;
                v.model = _liverSuifang.viralInfectionDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 10: //移植肝超声检查
            {
                LiverTranSonoViewController *v = [LiverTranSonoViewController new];
                v.delegate = self;
                v.livertransono = _liverSuifang.liverTranSonoDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 11: //肝脏异常回声光团
            {
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LiverAbnormalEcho" bundle:[NSBundle mainBundle]];
                LiverAbnormalEchoViewController *v =[sb instantiateViewControllerWithIdentifier:@"LiverAbnormalEchoVC"];
                v.delegate = self;
                v.model = _liverSuifang.abnormalHepaticEchoDTO;
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            default:
                break;
        }
    }
    else if (indexPath.section==8){ //用药方案
        TabletPlanViewController *v = [TabletPlanViewController new];
        v.delegate = self;
        v.isOnlyLocal = YES;
        v.plan = _liverSuifang.sickMedicinePlanDTO;
        v.index = indexPath.row;
        UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:v];
        [self presentViewController:navi animated:YES completion:nil];
    }
    else if(indexPath.section==9){
        SinglelineTextFormViewController *inputv = [SinglelineTextFormViewController new];
        inputv.delegate = self;
        inputv.indexPath = indexPath;
        inputv.title = @"输入事件内容";
        [self.navigationController pushViewController:inputv animated:YES];
    }
}

#pragma mark - UI响应
- (void)timeTypeBtnClick:(UIButton*)sender{
    IQActionSheetPickerView *picker = [[IQActionSheetPickerView alloc] initWithTitle:@"" delegate:self];
    [picker setTag:sender.tag];
    [picker setActionSheetPickerStyle:IQActionSheetPickerStyleDatePicker];
    [picker show];
}

#pragma mark - IQActionSheetPickerViewDelegate
- (void)actionSheetPickerView:(IQActionSheetPickerView *)pickerView didSelectDate:(NSDate *)date{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateStr = [formatter stringFromDate:date];
    NSIndexPath *ip = DEROWINDEX(pickerView.tag);
    if (ip.section==0){
        _liverSuifang.visitType = dateStr;
    }
    else if (ip.section==1) {
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:ip];
        cell.detailTextLabel.text = dateStr;
        _liverSuifang.visitTime = dateStr;
    }
    [self.tableView deselectRowAtIndexPath:ip animated:YES];
}

#pragma mark - 图片控件代理 DzyImagePicker delegate
- (void)getBase64Images:(NSArray *)imgData index:(NSInteger)tag{
    if (imgData.count==0) {
        return;
    }
    NSString *propertyName = [self.picPropertyNameIndexDic objectForKey:[NSNumber numberWithInteger:tag]];
    [_liverSuifang setValue:imgData[0] forKey:propertyName];
}
#pragma mark - DailyIndicatorControllerDelegate
- (void)backDailyindicatorData:(RPDailyIndicatorBean *)data{
    _liverSuifang.dailyIndicatorDTO = data;
}
#pragma mark - RoutineBloodViewControllerDelegate
- (void)backRoutinebloodData:(RPOutinebloodBean *)data{
    _liverSuifang.routineBloodDTO = data;
}
#pragma mark - TabletPlanViewBackDelegate
- (void)backTabletPlan:(RPMedicinePlan *)plan index:(long)index{
    _liverSuifang.sickMedicinePlanDTO = plan;
}
#pragma mark - UrinalysisViewControllerDelegate
- (void)backUrinalysisData:(RPUrinalysisBean *)data{
    _liverSuifang.urinalysisDTO = data;
}
#pragma mark - LiverViewControllerDelegate
- (void)backLiver:(RPLiverBean *)data{
    _liverSuifang.liverDTO = data;
}
#pragma mark - RenalViewControllerDelegate
- (void)backRenal:(RPRenalBean *)data{
    _liverSuifang.renalDTO = data;
}
#pragma mark - BloodsugarViewControllerDelegate
- (void)backBloodsugar:(RPBloodsugar *)data{
    _liverSuifang.bloodSugarDTO = data;
}
#pragma mark - BloodfatViewControllerDelegate
- (void)backBloodfat:(RPBloodfatBean *)data{
    _liverSuifang.bloodFatDTO = data;
}
#pragma mark - TumorMarkerViewControllerDelegate
- (void)backTumormarker:(RPTumormarkerBean *)data{
    _liverSuifang.tumorMarkerDTO = data;
}
#pragma mark - ImSupViewControllerDelegate
- (void)backImSup:(RPImSupConcentrationBean *)data{
    _liverSuifang.imSupConcentrationDTO = data;
}
#pragma mark - LiverTranSonoViewControllerDelegate
- (void)backLiverTransono:(RPLiverTranSonoBean *)data{
    _liverSuifang.liverTranSonoDTO = data;
}
#pragma mark - LiverAbnormalEchoViewControllerDelegate
- (void)backLiverAbnormalEcho:(RPAbnormalHepaticEchoBean *)data{
    _liverSuifang.abnormalHepaticEchoDTO = data;
}
#pragma mark - VirusInflectionViewControllerDelegate
- (void)backViralInflectionData:(RPViralInflectionBean *)data{
    _liverSuifang.viralInfectionDTO = data;
}
#pragma mark - SinglelineTextFormViewControllerDelegate
- (void)backData:(NSString *)content identifier:(NSIndexPath *)indexPath{
    if (indexPath.row==1) { //再次入院事件
        _liverSuifang.event = content;
    }
    else if (indexPath.row==3) { //其它事件
        _liverSuifang.otherEvents = content;
    }
}

#pragma mark - 内部函数
//创建图片控件
- (DzyImgPicker*)createImgPicker{
    DzyImgPicker *imgPicker = [[DzyImgPicker alloc] initWithFrame:CGRectMake(10, 30, SCREEN_WIDTH-20, 100) andParentV:self andMaxNum:1];
    imgPicker.dzyImgDelegate = self;
    return imgPicker;
}

//发起图片请求
- (void)requestPictures:(NSString*)urlArrStr ctrlIndex:(NSNumber*)index{
    if (![urlArrStr isNotEmpty]) {
        return;
    }
    NSMutableArray *urlArr = [[urlArrStr componentsSeparatedByString:@","] mutableCopy];
    if (((NSString*)urlArr.lastObject).length==0) {
        [urlArr removeLastObject];
    }
    NSMutableArray *tempImageArr = [NSMutableArray array];
    for (NSString *url in urlArr) {
        NSURL *ourl = [NSURL URLWithString:url];
        UIImageView *iv = [[UIImageView alloc] init];
        [_picCacheArr addObject:iv];
        [iv sd_setImageWithURL:ourl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (image) {
                [tempImageArr addObject:image];
                if (tempImageArr.count == urlArr.count) {
                    DzyImgPicker *picker = [_imgPickerDic objectForKey:index];
                    [picker giveImages:tempImageArr];
                }
            }
        }];
    }
    [_picCacheDic setObject:@1 forKey:index];
}

#pragma mark - 数据配置
- (NSMutableArray*)indexArr{
    if (!_indexArr) {
        _indexArr = [NSMutableArray array];
    }
    return _indexArr;
}
- (NSDictionary *)picPropertyNameFlectDic{
    if (!_picPropertyNameFlectDic) {
        _picPropertyNameFlectDic = @{@"肝脏其它异常":@"otherAbnormalities", @"肝脏CT":@"liverCT", @"肺部CT/胸片":@"lungCT",
                                     @"全身骨扫描":@"boneImaging", @"其它":@"other"};
    }
    return _picPropertyNameFlectDic;
}
- (NSMutableDictionary *)picPropertyNameIndexDic{
    if (!_picPropertyNameIndexDic) {
        _picPropertyNameIndexDic = [NSMutableDictionary dictionary];
    }
    return _picPropertyNameIndexDic;
}

@end
